/*
 * File Name : my_string.cpp
 * Auther : dream.liuguobiao
 * Create Date : 2010-5-16
 * Last Edit : 2010-5-16
 */
#include <string>
#include <queue>
#include "my_string.h"

#include <termios.h>
#include <unistd.h>
#include <stdio.h>

my_string *my_string::instance_my_string = NULL ;

my_string::my_string()
:sub_string("")
{
}

std::string *my_string::get_sub_string( std::string &input_string ){
  size_t found = input_string.find_first_of( " " );
    sub_string = input_string.substr( 0 , found );
  if( std::string::npos != found )
    input_string.erase( 0 ,found +1);
  else
    input_string.erase( 0 ,found);
  return &sub_string;
}

my_string *my_string::get_my_string(){
  if( NULL == instance_my_string )
    instance_my_string = new my_string();
  return instance_my_string;
}


std::queue<std::string> *my_string::split_string( char dot, std::string &input_string){
  size_t size_of_split_string = split_string_result.size();
  for(int i = 0; i<(int)size_of_split_string; i++)
    split_string_result.pop();

  if( dot == input_string[0] )
    input_string.erase( 0,1);
  size_t found =  input_string.find_first_of( dot );
  while( std::string::npos != found){
    std::string sub_string = input_string.substr( 0 , found );
    split_string_result.push( sub_string );
    input_string.erase( 0 ,found +1);
    found =  input_string.find_first_of( dot );
  }
  if( (std::string)""  != input_string)
    split_string_result.push( input_string );
  return &split_string_result;
}

int my_string::mygetch(void)
{
struct termios oldt, newt;
int ch; 
tcgetattr( STDIN_FILENO, &oldt ); // 记录旧设置
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt ); // 设置新的
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); // 设置旧的
return ch;
}
